package com.hkzhao.shixun.component;

import com.hkzhao.shixun.dto.QueueEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <h3>j2ee</h3>
 * <p>取消中奖信息的生产者</p>
 *
 * @author : hkzhao
 * @date : 2020-06-06 17:57
 **/

@Component
public class CancleLotteryRecordSender {
    private static final Logger LOOGER = LoggerFactory.getLogger(CancleLotteryRecordSender.class);
    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendMessage(String RecordId,Long delayTimes){
        //给死信队列发消息
        amqpTemplate.convertAndSend(QueueEnum.QUEUE_ENUM_CancleLottery_TTL.getExchange(), QueueEnum.QUEUE_ENUM_CancleLottery_TTL.getRouteKey(), RecordId, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
                return message;
            }
        });
    }
}

